package com.yingjie.yingjieauth.controller;

import com.yingjie.commonbase.bo.UserAuthBo;
import com.yingjie.commonbase.commons.ReturnCodeMsg;
import com.yingjie.commonbase.commons.ReturnObject;
import com.yingjie.yingjieauth.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class UserAuthController {
    @Resource
    private UserService userService;
    //   检测用户能否正常使用，返回用户权限
    @PostMapping("/userAuth")
    public ReturnObject<UserAuthBo> userAuth(@RequestParam("userId") Integer userId){
        System.out.println(userId);
        UserAuthBo userAuthBo = userService.userAuth(userId);
        if(userAuthBo==null){
            //用户不存在
            return ReturnObject.ERROR(ReturnCodeMsg.NO_USER);
        }
        if(userAuthBo.getUserStatus()==0){
            //用户被禁用
            return ReturnObject.ERROR(ReturnCodeMsg.NO_DISABLE);
        }
        return ReturnObject.SUCCESS(userAuthBo);
    }

}
